import Vue from "vue";
import VueRouter from "vue-router";
// 使用插件
Vue.use(VueRouter);
// 导入路由组件
import Home from "@/pages/Home"
import Login from "@/pages/Login"
import Register from "@/pages/Register"
import Search from "@/pages/Search"

let originPush = VueRouter.prototype.push;
let originReplace = VueRouter.prototype.replace;
VueRouter.prototype.push = function(location, resolve, reject) {
    if (resolve && reject) {
        originPush.call(this, location, resolve, reject)
    } else {
        originPush.call(this, location, () => {}, () => {})
    }
}
VueRouter.prototype.replace = function(location, resolve, reject) {
    if (resolve && reject) {
        originReplace.call(this, location, resolve, reject)
    } else {
        originReplace.call(this, location, () => {}, () => {})
    }
}

// 配置路由
export default new VueRouter({
    routes: [{
        name: "home",
        path: "/home",
        component: Home,
        meta: {
            show: true /* footer组件的显示与隐藏*/ ,

        }
    }, {
        name: "login",
        path: "/login",
        component: Login,
        meta: { show: false }
    }, {
        name: "register",
        path: "/register",
        component: Register,
        meta: { show: false },
    }, {
        name: "search",
        path: "/search/:keyWord?",
        component: Search,
        meta: { show: true }
    }, {
        path: "*",
        redirect: "/home"
    }]
})